#!/usr/bin/env node

const Koa = require('koa'),//需要Koa实例化对象，所以要大写
      log = console.log;

let app = new Koa();

app.use(async (c,next)=>{// M-logger
  log(`${c.method} ${c.path}`);
  let time = await next();
  log(time);
});

app.use(async (c,next)=>{// M-ms
  let start = Date.now();
  await next();
  let end = Date.now();

  //法一
  c.time = end - start;

  //法二
  return end-start;

  //法三：响应头传数据
  
  //log(`${end-start} ms`);
})

app.use((c,next)=>{// M-hello
  log('hello koa');
  c.body = 'hello koa';
});


app.listen(8080);


